
package org.jetnuke.dao.hsqldb;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

import net.jforum.JForumExecutionContext;
import net.jforum.util.preferences.SystemGlobals;

import org.jetnuke.dao.generic.GenericDownloadDownloadDAO;

public class HsqldbDownloadDownloadDAO extends GenericDownloadDownloadDAO {

	public List search(String title, String description, int start, int rowcount) throws Exception {
		PreparedStatement p =JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("DownloadDownloadModel.search"));
		p.setInt(1,start);	
		p.setInt(2,rowcount);

		p.setString(3,title);
		p.setString(4, description);
		
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();
		
		return list;
	}

	public List selectDateAsc(int cid, int start, int rowcount) throws Exception {
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("DownloadDownloadModel.selectDateAsc"));
		p.setInt(3,cid);	
		p.setInt(1,start);
		p.setInt(2,rowcount);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();
		
		return list;
	}

	public List selectDateDesc(int cid, int start, int count) throws Exception {
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("DownloadDownloadModel.selectDateDesc"));
		p.setInt(3,cid);	
		p.setInt(1,start);
		p.setInt(2,count);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();
		
		return list;
	}

	public List selectHitsAsc(int cid, int start, int count) throws Exception {
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("DownloadDownloadModel.selectHitsAsc"));
		p.setInt(3,cid);	
		p.setInt(1,start);
		p.setInt(2,count);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();
		
		return list;
	}

	public List selectHitsDesc(int cid, int start, int count) throws Exception {
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("DownloadDownloadModel.selectHitsDesc"));
		p.setInt(3,cid);	
		p.setInt(1,start);
		p.setInt(2,count);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();
		
		return list;
	}

	public List selectRatingAsc(int cid, int start, int count) throws Exception {
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("DownloadDownloadModel.selectRatingAsc"));
		p.setInt(3,cid);	
		p.setInt(1,start);
		p.setInt(2,count);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();
		
		return list;
	}

	public List selectRatingDesc(int cid, int start, int count) throws Exception {
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("DownloadDownloadModel.selectRatingDesc"));
		p.setInt(3,cid);	
		p.setInt(1,start);
		p.setInt(2,count);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();
		
		return list;
	}

	public List selectTitleAsc(int cid, int start, int count) throws Exception {
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("DownloadDownloadModel.selectTitleAsc"));
		p.setInt(3,cid);	
		p.setInt(1,start);
		p.setInt(2,count);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();
		
		return list;
	}

	public List selectTitleDesc(int cid, int start, int count) throws Exception {
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("DownloadDownloadModel.selectTitleDesc"));
		p.setInt(3,cid);	
		p.setInt(1,start);
		p.setInt(2,count);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();
		
		return list;
	}

}
